package com.ysd.shopcar.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: majl
 * @DateTime: 2019-5-20
 * @FileName: DateUtil
 * @Description
 */
public class DateUtil {
    public static String DF_YMD_HMS = "yyyy-MM-dd HH:mm:ss";
    public static String DF_YMD = "yyyy-MM-dd";

    public static String dateToString(Date date){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DF_YMD_HMS);
            return sdf.format(date);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 判断日期格式是否为yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static boolean isFullDate(String date){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DF_YMD_HMS);
            sdf.parse(date);
            return true;
        }catch (Exception e){
        }
        return false;
    }

    /**
     * 判断日期格式是否为yyyy-MM-dd
     * @param date
     * @return
     */
    public static boolean isDateDay(String date){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(DF_YMD_HMS);
            sdf.parse(date);
            return true;
        }catch (Exception e){
        }
        return false;
    }
    public static String dateToString(Date date,String pattern){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            return sdf.format(date);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    
}
